﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fis.Win.Forms
{
    public partial class ListForm : BaseForm, Fis.Win.Utils.IDataTrans
    {
        public string RightsName { get; set; }
        public bool ShowBarManager
        {
            set { bar2.Visible = value; }
        }

        public ListForm()
        {
            InitializeComponent();
        }

        private void iNew_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Fis.Win.Utils.AppSession.RightsValidata(RightsName, "AddNew"))
                NewProcess();
        }

        private void iEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Fis.Win.Utils.AppSession.RightsValidata(RightsName, "Modify"))
                EditProcess();
        }

        private void iDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Fis.Win.Utils.AppSession.RightsValidata(RightsName, "Delete"))
                DelProcess();
        }

        protected virtual void NewProcess() { }
        protected virtual void EditProcess() { }
        protected virtual void DelProcess() { }
        protected virtual void FindProcess(string value) { }
        protected virtual void RefreshProcess()
        {
            ViewModel = ViewProvider.InitializeViewModel(ViewModel);
            InitializeBinding();
        }

        protected virtual void ExportProcess(string file)
        {

        }

        public override string Message
        {
            get
            {
                return iMessage.Caption;
            }
            set
            {
                iMessage.Caption = value;
                ShowMessage(value);
            }
        }

        private void riFind_EditValueChanged(object sender, EventArgs e)
        {
            FindProcess((sender as DevExpress.XtraEditors.TextEdit).Text);
        }

        private void iRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            RefreshProcess();
        }

        public virtual void ToXls(string path)
        {

        }

        public virtual string FromXls(string path)
        {
            return string.Empty;
        }

        private void iExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Filter = "Excel文件 (*.xls)|*.xls";

                if (DialogResult.OK == dlg.ShowDialog())
                {
                    ExportProcess(dlg.FileName);
                    DevExpress.XtraEditors.XtraMessageBox.Show("导出成功");
                }
            }
        }
    }
}
